package top.datacluster.basic.sort;

/**
 * 选择排序的简单实现
 */
public class SelectSort {

    public void sort(Comparable[] data){

        for (int i = 0; i < data.length; i++){
            int min = i;
            for (int j = i + 1; j < data.length; j++){
                if (data[i].compareTo(data[j]) > 0){
                    min = j;
                }
            }
            Comparable temp = data[i];
            data[i] = data[min];
            data[min] = temp;
        }
    }

    public void print(Comparable[] data){
        for (int i = 0; i < data.length; i++){
            System.out.print(data[i] + " ");
        }
    }

    public static void main(String[] args) {
        Integer[] test = new Integer[]{3, 2, 5, 10, 7};
        SelectSort sort = new SelectSort();
        sort.sort(test);
        sort.print(test);

    }

}
